#include"PersonPageModule.h"
//绘制个人主页
void drawPersonPage(User U, int chose) {
	for (int i = 0; i < 10; i++) {
		cout << endl;
	}
	Element::drawStruct();
	cout << "|个人主页|" << endl;
	Element::drawLine();
	cout << "Username:" << U.getUserName() << endl;
	Element::drawLine();
	if (chose == 0) {
		Color::Blue();
		cout << "个性签名" << endl;
		Color::White();
	}
	else {
		cout << "个性签名" << endl;
	}
	Signature();
	Element::drawLine();
	if (chose == 1) {
		Color::Blue();
		cout << "修改用户名或密码" << endl;
		Color::White();
	}
	else {
		cout << "修改用户名或密码" << endl;
	}
	Element::drawLine();
	if (chose == 2) {
		Color::Blue();
		cout << "修改计划" << endl;
		Color::White();
	}
	else {
		cout << "修改计划" << endl;
	}
	Element::drawLine();
	if (chose == 3) {
		Color::Blue();
		cout << "心情日记" << endl;
		Color::White();
	}
	else {
		cout << "心情日记" << endl;
	}
	Element::drawStruct();
}

//修改用户名或密码
void change(User& U) {
	Element::drawStruct();
	string name;
	string password;
	bool type = false;
	while (1) {
		cout << setw(25) << "原用户名:" << U.getUserName() << endl;
		cout << setw(25) << "输入原密码:";
		cin >> password;
		Element::drawLine();
		if (password == U.getPassWord()) {
			cout << setw(25) << "输入新用户名:";
			cin >> name;
			cout << setw(25) << "输入新密码:";
			cin >> password;
			Element::drawLine();
			cout << right << "请按Enter键确认修改..." << endl;
			cout << right << "请按Esc键取消修改....." << endl;
			type = true;
		}
		else {
			Color::Red();
			cout << setw(31) << "原密码错误..." << endl;
			Color::White();
			Element::drawLine();
			cout << right << "按Enter键重试." << endl;
			cout << right << "按Esc键退出..." << endl;

		}
		char a = _getch();
		while (a != VK_RETURN && a != VK_ESCAPE)
			a = _getch();
		if (a == VK_RETURN) {
			if (type) {
				U.changeUserName(name);
				U.changePassWord(password);
				system("cls");
				cout << setw(29) << "已修改" << endl;
				Sleep(2000);
				break;
			}
			else {
				system("cls");
				continue;
			}
		}
		else {
			if (type) {
				system("cls");
				cout << setw(29) << "未修改" << endl;
				Sleep(1000);
			}
			break;
		}
	}
}

//个性签名
void Signature(bool N) {
	if (N) {
		ifstream R_File;
		R_File.open("Signture.txt", ios::in);
		if (!R_File) {
			cout << "New day,New start!" << endl;
		}
		else {
			string s;
			while (getline(R_File,s)) {
				cout << s;
			}
			cout << endl;
		}
		R_File.close();
	}
	else {
		Element::drawStruct();
		cout << "修改个性签名" << endl;
		Element::drawLine();
		cout << "|请输入新的个性签名|" << endl;
		string s;
		getline(cin, s);
		Element::drawLine();
		cout << right << "请按Enter键确认修改..." << endl;
		cout << right << "请按Esc键取消修改....." << endl;
		Element::drawStruct();
		char a = _getch();
		while (a != VK_RETURN && a != VK_ESCAPE)
			a = _getch();
		if (a == VK_RETURN) {
			ofstream W_File;
			W_File.open("Signture.txt", ios::out);
			W_File << s;
			W_File.close();
		}
	}
}

//修改计划
void changePlan(User& U) {
	Element::drawStruct();
	cout << setw(23) << "原计划:" << U.getDayWantNumber() << endl;
	Element::drawLine();
	cout << setw(23) << "输入你的计划:";
	int number;
	cin >> number;
	cout << right << "请按Enter键确认修改..." << endl;
	cout << right << "请按Esc键取消修改....." << endl;
	char a = _getch();
	while (a != VK_RETURN && a != VK_ESCAPE)
		a = _getch();
	if (a == VK_RETURN) {
		U.changeDayWantNumber(number);
		system("cls");
		cout << setw(29) << "已修改" << endl;
		Sleep(2000);
		break;
	}
	else{
		system("cls");
		cout << setw(29) << "未修改" << endl;
		Sleep(2000);
		break;
	}
}

//心情日记(未完成)
void moodDairy() {
	
}
//控制个人主页
void controlPersonPage(User& U, int* p) {
	drawInterface(U, 2);
	drawPersonPage(U, *p);
	while (1) {
		char a = _getch();
		while (a != VK_RETURN && a != VK_TAB) {
			if (a == 'w' && *p != 0) {
				p--;
				system("cls");
				drawInterface(U, 2);
				drawPersonPage(U, *p);
			}
			if (a == 's' && *p != 3) {
				p++;
				system("cls");
				drawInterface(U, 2);
				drawPersonPage(U, *p);
			}
			a = _getch();
		}
		system("cls");
		if (a == VK_TAB) {			
			break;
		}
		if (*p == 0) {
			Signature(0);
		}
		else if (*p == 1) {
			change(U);
		}
		else if (*p == 2) {	
			changePlan(U);
		}
		else {
			
			moodDairy();
		}
		system("cls");
		drawInterface(U, 2);
		drawPersonPage(U, *p);
	}
}